package top.laoshuzi.cloudplatform.servo.bean;

import java.util.List;

import top.laoshuzi.photinia.rest.protocol.FrameParcel;
import top.laoshuzi.photinia.rest.protocol.FrameParcelable;

/**
 * Created by mouse on 2017/12/28.
 */

public class ServoControlBean implements FrameParcelable {

    private List<ControlBean> controlBeans;

    public ServoControlBean() {
    }

    public ServoControlBean(FrameParcel frameParcel) {
        controlBeans = frameParcel.readParcelableArrayList(ControlBean.CREATE);
    }

    public static final Creator<ServoControlBean> CREATE = new Creator<ServoControlBean>() {
        @Override
        public ServoControlBean createFromParce(FrameParcel frameParcel) {
            return new ServoControlBean(frameParcel);
        }

        @Override
        public ServoControlBean[] newArray(int i) {
            return new ServoControlBean[i];
        }
    };

    @Override
    public void writeToParce(FrameParcel frameParcel) {
        frameParcel.writeParcelableArrayList(controlBeans);
    }

    public List<ControlBean> getControlBeans() {
        return controlBeans;
    }

    public void setControlBeans(List<ControlBean> controlBeans) {
        this.controlBeans = controlBeans;
    }

    public static class ControlBean implements FrameParcelable {

        private int code;
        private int angle;

        public ControlBean() {
        }

        public ControlBean(FrameParcel frameParcel) {
            code = frameParcel.readByte();
            angle = frameParcel.readShort();
        }

        public static final Creator<ControlBean> CREATE = new Creator<ControlBean>() {
            @Override
            public ControlBean createFromParce(FrameParcel frameParcel) {
                return new ControlBean(frameParcel);
            }

            @Override
            public ControlBean[] newArray(int i) {
                return new ControlBean[i];
            }
        };

        @Override
        public void writeToParce(FrameParcel frameParcel) {
            frameParcel.writeByte((byte) code);
            frameParcel.writeShort((short) angle);
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public int getAngle() {
            return angle;
        }

        public void setAngle(int angle) {
            this.angle = angle;
        }
    }
}
